package com.yet.kotlinapp.modules.login

import android.content.Context
import android.content.Intent
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.kongzue.dialogx.dialogs.WaitDialog
import com.yet.kotlinapp.api.WangAndroidApi
import com.yet.kotlinapp.entity.LoginResponseInfo
import com.yet.kotlinapp.modules.login.inter.LoginModel
import com.yet.kotlinapp.modules.login.inter.LoginPresenter
import com.yet.kotlinapp.modules.regist.RegisterActivity
import com.yet.kotlinapp.net.ApiClient
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers

/**
 *
 * @ProjectName: Kotlin app
 * @Package: com.yet.kotlinapp.modules.login
 * @ClassName: LoginModelImp
 * @Description: java类作用描述
 * @Author: liys
 * @CreateDate: 2021/8/27 13:50
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/8/27 13:50
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
class LoginModelImp :LoginModel{




    override fun login(username: String, pw: String, presenter: LoginPresenter.OnLoginActionListener) {
        ApiClient.instance.instanceRetrofit(WangAndroidApi::class.java)
            .loginAction(username,pw)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<LoginResponseInfo> {
                override fun onSubscribe(d: Disposable?) {
                    WaitDialog.show("Please Wait!");
                }

                override fun onNext(t: LoginResponseInfo?) {
                    LogUtils.d(t.toString());
                    presenter.loginSuccess(t);
                }

                override fun onError(e: Throwable?) {

                    e?.printStackTrace()
                    WaitDialog.dismiss()
                }

                override fun onComplete() {
                    LogUtils.d("onComplete");
                    WaitDialog.dismiss()
                }
            })
    }


}